<template>
  <div class="login">
    <router-view></router-view>
    <router-link to="/RegisterView">面经注册</router-link>
    <hr />
    <div class="username">
      <p class="usn">用户名</p>
      <input type="text" class="usi" placeholder="用户名"  v-model="username"/>
    </div>
    <hr />

    <div class="password">
      <p class="psd">密码</p>
      <input type="password" class="psi" placeholder="密码"  v-model="password"/>
    </div>
    <hr />
    <button class="loginbtn" @click="registerinfo">提交</button>
    <p class="register" @click="register">有账号,去登录</p>
  </div>
</template>

<script>
import axios from "axios";

export default {
  data() {
    return {
      username: "",
      password: "",
    };
  },
  name: "RegisterView",
  methods: {
    register() {
      this.$router.push("/LoginView");
    },
    async registerinfo() {
      await axios({
        url: "http://interview-api-t.itheima.net/h5/user/register",
        method: "POST",
        data: {
          username: this.username,
          password: this.password,
        },
      });
      alert("注册成功");
      this.$router.push("/LoginView");
    },
  },
};
</script>

<style lang="less" scoped>
* {
  margin: 0;
  padding: 0;
}
.login {
  padding: 10px;
  position: relative;
}
.active {
  //设置成块元素
  display: block;
  font-size: 20px;
  width: 100%;
  line-height: 100%;
  text-decoration: none;
  color: #333;
  text-align: center;
  margin: 30px 0;
}

.username {
  width: 100%;
  display: flex;
  margin: 10px 0;

  .usi {
    font-size: 20px;

    flex: 1;
    border: none;
    padding: 5px;
    outline: none;
    align-items: center;

    &:focus {
      border: none;
    }
  }
  .usn {
    width: 100px;
    font-size: 20px;
    text-align: start;

    color: #333;
  }
}
.password {
  width: 100%;

  display: flex;
  margin: 10px 0;
  font-size: 20px;
  .psi {
    font-size: 20px;

    flex: 1;
    border: none;
    padding: 5px;
    outline: none;
    align-items: center;

    &:focus {
      border: none;
    }
  }
  .psd {
    font-size: 20px;
    width: 100px;

    text-align: start;

    color: #333;
  }
}
.loginbtn {
  width: 100%;
  height: 50px;
  background-color: #07c160;
  color: white;
  margin: 15px 0;
  border: none;
  border-radius: 5px;
}
.register {
  position: absolute;
  right: 10px;
  color: #007cc4;
  font-size: 12px;
}
</style>
